package com.zx.mes.webmvc.hyl.advice;

import com.zx.mes.webmvc.hyl.response.BaseResponse;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * controller advice 全局异常捕获
 *
 * @author huayunlong
 * @date 2018-8-13
 */
@RestControllerAdvice
public class ExceptionControllerAdvice {

//    @ExceptionHandler(Exception.class)
//    public ResponseEntity<String> handle(Exception e) {
//
//        return ResponseEntity.ok(e.getMessage());
//
//    }

    @ExceptionHandler(Exception.class)
    public ResponseEntity<BaseResponse> handle(Exception e) {
        BaseResponse response = new BaseResponse(500, e.getMessage());
        return ResponseEntity.ok(response);

    }
}
